
/*
 * @file gkt_screen.h
 */

#ifndef GKT_SCREEN_H
#define GKT_SCREEN_H

#include "gkt_types.h"

#ifdef __cplusplus
extern "C" {
#endif

#if defined(GKT_CONFIG_SCREEN_ENABLE) && GKT_CONFIG_SCREEN_ENABLE

/* pixel format */
#define GKT_SCREEN_PF_MONOCHROME	0	/* single color / black-white */
#define GKT_SCREEN_PF_CLUT8		1	/* 8-bits Color Look-Up Table */
#define GKT_SCREEN_PF_GRAY256	2	/* 256 gray levels */
#define GKT_SCREEN_PF_RGB565	3	/* 16-bits RGB565 */
#define GKT_SCREEN_PF_RGB888	4	/* 24-bits RGB888 */

/* dot matrix format */
#define GKT_SCREEN_DMF_ROW	0
#define GKT_SCREEN_DMF_COL	1
#define GKT_SCREEN_DMF_COL_ROW	2
#define GKT_SCREEN_DMF_ROW_COL	3

#include "gkt_screen_defines.h"

#if (GKT_SCREEN_PF_MONOCHROME == GKT_SCREEN_PF)
typedef uint8_t		gkt_color_t;
#define GKT_COLOR(red, green, blue)	\
	((((red) < 0x40) && ((green) < 0x40) && ((blue) < 0x40)) ? 0 : 1)
#elif (GKT_SCREEN_PF_RGB565 == GKT_SCREEN_PF)
typedef uint16_t	gkt_color_t;
#define GKT_COLOR(red, green, blue)	\
	((((gkt_color_t)(red) & 0x00f1) << 8) \
		| (((gkt_color_t)(green) & 0xfc) << 3) \
		| (((gkt_color_t)(blue) & 0xf1) >> 3))
#elif (GKT_SCREEN_PF_RGB888 == GKT_SCREEN_PF)
typedef uint32_t	gkt_color_t;
#define GKT_COLOR(red, green, blue)	\
	(((gkt_color_t)(red) << 16) | ((gkt_color_t)(green) << 8) \
		| (gkt_color_t)(blue))
#else
#error "Not Implement Yet!"
#endif

#define GKT_COLOR_WHITE		GKT_COLOR(0xff, 0xff, 0xff)
#define GKT_COLOR_BLACK		GKT_COLOR(0, 0, 0)
#define GKT_COLOR_RED		GKT_COLOR(0xff, 0, 0)
#define GKT_COLOR_GREEN		GKT_COLOR(00, 0xff, 0)
#define GKT_COLOR_BLUE		GKT_COLOR(0, 0, 0xff)
#define GKT_COLOR_YELLOW	GKT_COLOR(0xff, 0xff, 0)
#define GKT_COLOR_ORANGE	GKT_COLOR(0xff, 0x99, 0)

typedef enum _gkt_screen_ctrl {
	GKT_SCREEN_CTRL_POWEROFF = 0,
	GKT_SCREEN_CTRL_POWERON,
	GKT_SCREEN_CTRL_RESET,
	GKT_SCREEN_CTRL_SLEEP,
	GKT_SCREEN_CTRL_WAKEUP,

	GKT_SCREEN_CTRL_DISPLAY_OFF,
	GKT_SCREEN_CTRL_DISPLAY_ON,
	GKT_SCREEN_CTRL_DISPLAY_CLEAR,

	GKT_SCREEN_CTRL_SCROLL_CONFIG,
	GKT_SCREEN_CTRL_SCROLL_START,
	GKT_SCREEN_CTRL_SCROLL_STOP,

	GKT_SCREEN_CTRL_MAX
} gkt_screen_ctrl_e;

/* SCROLL */
typedef enum _gkt_screen_scroll_direction {
	GKT_SCREEN_SCROLL_LEFT = 0,
	GKT_SCREEN_SCROLL_RIGHT,
	GKT_SCREEN_SCROLL_UP,
	GKT_SCREEN_SCROLL_DOWN,
	GKT_SCREEN_SCROLL_DIR_INVALID
} gkt_screen_scroll_direction_e;

typedef enum _gkt_screen_scroll_speed {
	GKT_SCREEN_SCROLL_ULTRA_SLOW = 0,
	GKT_SCREEN_SCROLL_SLOW,
	GKT_SCREEN_SCROLL_NORMAL,
	GKT_SCREEN_SCROLL_FAST,
	GKT_SCREEN_SCROLL_ULTRA_FAST,
	GKT_SCREEN_SCROLL_SPEED_INVALID
} gkt_screen_scroll_speed_e;

typedef struct _gkt_screen_scroll_params {
	gkt_screen_scroll_direction_e	direction;
	gkt_screen_scroll_speed_e	speed;
	uint32_t	start;	/* SCROLL_LEFT/RIGHT: row start
						 * SCROLL_UP/DOWN   : col start */
	uint32_t	nums;	/* SCROLL_LEFT/RIGHT: row nums
						 * SCROLL_UP/DOWN   : col nums */
} gkt_screen_scroll_params_s;

int gkt_screen_init(void);

/************************************************************
 * @function - gkt_screen_draw_bitmap
 * @brief    - draw bitmap in rect, usually used by drawing font
 * @params
 *   bitmap    [in] bitmap
 *                  the bitmap DMF should be in agreement with the screen
 *   rect      [in] draw rectangle
 *   fg_color  [in] foreground color
 *   bg_color  [in] background color
 *   update    [in] display or not(in cache)
 ************************************************************/
int gkt_screen_draw_bitmap(const void *bitmap, 
			const gkt_rect_s *rect, gkt_color_t fg_color, 
			gkt_color_t bg_color, int update);

int gkt_screen_draw_hline(uint16_t x, uint16_t y, 
		uint16_t width, gkt_color_t color, int update);

int gkt_screen_draw_vline(uint16_t x, uint16_t y, 
		uint16_t height, gkt_color_t color, int update);

/************************************************************
 * @function - gkt_screen_fill
 * @brief	 - fill rect with specified color
 * @params
 *	 rect	   [in] rectangle, the whole screen if NULL
 *	 color     [in] color
 *	 update    [in] display or not(in cache)
 ************************************************************/
int gkt_screen_fill(const gkt_rect_s *rect, 
			gkt_color_t color, int update);

/************************************************************
 * @function - gkt_screen_update
 * @brief	 - update specified rect in cache
 * @params
 *	 rect	   [in] rectangle, the whole screen if NULL
 ************************************************************/
int gkt_screen_update(const gkt_rect_s *rect);

/************************************************************
 * @function - gkt_screen_control
 * @brief	 - screen control
 * @params
 *	 ctrl	    [in] control op
 *   ext_params [in] extended params
 *                   some ctrl_op does not need the extended params
 ************************************************************/
int gkt_screen_control(gkt_screen_ctrl_e ctrl, uint32_t ext_params);

#endif

#ifdef __cplusplus
}
#endif

#endif	/* GKT_SCREEN_H */


